#ifndef _LIST_H_
#define _LIST_H_


#include <stdlib.h>

typedef struct list_node {
	void 				*data;
	struct list_node 	*next;
}list_node_t;


typedef struct list {
	unsigned int 		size;
	
	void 				(*destroy)(void *data);
	int					(*match)(const void *key1, const void *key2);

	list_node_t			*head;
	list_node_t			*tail;
}list_t;

void list_init(list_t *list, void (*destroy)(void *data));
void list_destroy(list_t *list);
int list_insert_next(list_t *list, list_node_t *l, const void *data);
int list_remove_next(list_t *list, list_node_t *l, void **data);

#define list_size(list)			((list)->size)
#define list_head(list)			((list)->head)
#define list_tail(list)			((list)->tail)
#define list_is_head(list, node)	((node) == (list)->head ? 1 : 0)
#define list_is_tail(list, node)	((node)->next == NULL ? 1 : 0)
#define list_data(node)			((node)->data)
#define list_next(node)			((node)->next)

#endif /*_LIST_H_*/

